/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package usuarios;

import dataBase.Db;
import hate.ClasesMias;
import hate.EntradaSalida;
import inicio.arranca;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author martinLequerica
 */
public class crearVendedor extends JFrame {
    
    private String[] etiquetas={"Nombre","Apellido","Telefono","Direccion","Nombre Usuario","Contrasenia","identificador"};
    private JTextField[] text;
    private JButton aceptar,cancelar;
    private String creando;
    public crearVendedor(String foto){
        super("Crear Vendedor");
        creando=foto;
        text = new JTextField[7];
        setLayout(new GridLayout(etiquetas.length+1, 2));
        aceptar = new JButton("Aceptar");
        cancelar = new JButton("Cancelar");
        
        
        for (int i =0 ;i<etiquetas.length; i++){
            
            add(new JLabel(etiquetas[i]));
            text[i] = new JTextField();
            add(text[i]);
            
            
            
        }
        
        add(aceptar);
        add(cancelar);
        
        cancelar.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
           
                setVisible(false);
                if (creando.equals("no")){
                
                System.exit(0);
                }
                
            }
        });
        
        aceptar.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
           
                Db db = new Db();
                Statement st = db.getStatement();
                try {
                    boolean execute = st.execute("insert into vendedor (nombre,apellido,telefono,direccion,nombreUsuario,contrasenia,identificador) values ('"+text[0].getText()+"','"+text[1].getText()+"',"+Integer.parseInt(text[2].getText())+",'"+text[3].getText()+"','"+text[4].getText()+"','"+new EntradaSalida().hash(text[5].getText())+"','"+text[6].getText()+"')");
                    setVisible(false);
                    
                    if (creando != "si"){
                    new arranca();
                    }
                
                } catch (SQLException ex) {
                    Logger.getLogger(crearVendedor.class.getName()).log(Level.SEVERE, null, ex);
                }
                
            }
        });
        
        setLocation(400,400);
        setSize(260,260);
        setVisible(true);
        
        
        
        
    }
    
    
}
